/*
 * @Author: your name
 * @Date: 2020-01-02 15:32:58
 * @LastEditTime : 2020-02-11 18:19:46
 * @LastEditors  : Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \jxkh-web\src\services\publicMethods.js
 */
import axios from '../axios/index'
import { message, Select } from 'antd'
import React from 'react'
const { Option } = Select

/************************************************** 列表删除操作 **************************************************/
//删除一条数据后刷新列表
export function deleteRow(params) {
    const { methodType, url } = params
    return axios[methodType](url)
        .then((res) => {
            if (res.code === '1') {
                message.success("删除成功！");
            } else { message.error(`${res.msg}`) }
        })
}
//按查询条件查询、切换分页
export function queryList(params) {
    const { pagination, url, formData } = params
    let queryItems = {};
    if (pagination !== undefined) {
        const { current } = { ...pagination };
        Object.assign(queryItems, { current });
    }
    for (let item in formData) {
        if (formData[item] === undefined) formData[item] = '';
    }
    Object.assign(queryItems, formData);
    return axios.post(url, queryItems)
        .then((res) => { if (res.data !== null) { return res } })
}

/************************************************** 查询数据字典 **************************************************/

//查询职称
export function queryZc() {
    return axios.get(`/sjzd/selectSjzdByLx/79`)
        .then(res => {
            if (res.data !== null && res.data.length !== 0) {
                const Zc = res.data.map(item => <Option key={item.bh} value={item.bh}>{item.mc}</Option>)
                return Zc
            } else { message.warning('暂无数据') }
        })
}
//查询职务
export function queryZw() {
    return axios.get(`/sjzd/selectSjzdByLx/59`)
        .then(res => {
            if (res.data !== null && res.data.length !== 0) {
                const Zw = res.data.map(item => <Option key={item.bh} value={item.bh}>{item.mc}</Option>)
                return Zw
            } else { message.warning('暂无数据') }
        })
}
//查询来源
export function queryLy() {
    return axios.get('/sjzd/selectSjzdByLx/15').then(res => {
        if (res.data !== null && res.data.length !== 0) {
            const Lymc = res.data.map(item => <Option key={item.bh} value={item.bh}>{item.mc}</Option>)
            return Lymc
        } else { message.warning('暂无数据') }
    })
}
//查询单位
export function queryDw() {
    return axios.get('/sjzd/selectSjzdByLx/16').then(res => {
        if (res.data !== null && res.data.length !== 0) {
            const Dwmc = res.data.map(item => <Option key={item.bh} value={item.bh}>{item.mc}</Option>)
            return Dwmc
        } else { message.warning('暂无数据') }
    })
}
//查询上级名称
export function querySjmc() {
    return axios.get(`/sjzd/selectSjzdByLx/17`)
        .then((res) => {
            if (res.data !== null && res.data.length !== 0) {
                let Sjmc = res.data.map(item => <Option key={item.id} value={item.id}>{item.mc}</Option>);
                return Sjmc
            } else {
                message.warning('暂无数据')
            }
        })
}


/************************************************** 常用查询 **************************************************/
//机构下拉框获取焦点
export function queryJg(value) {
    return axios.get(`/jg/selectByJgz?search=${value}`)
        .then(res => {
            if (res.data !== null && res.data.length !== 0) {
                const Jgmc = res.data.map(item => <Option key={item.jgbm} value={item.jgbm}>{item.jgmc}</Option>)
                return Jgmc
            } else { message.warning('暂无数据') }
        })
}